package com.github.wxiaoqi.security.biz.biz;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.biz.entity.BhReceive;
import com.github.wxiaoqi.security.biz.entity.BhTask;
import com.github.wxiaoqi.security.biz.entity.BhTaskReceive;
import com.github.wxiaoqi.security.biz.entity.BhTaskUserResume;
import com.github.wxiaoqi.security.biz.mapper.BhReceiveMapper;
import com.github.wxiaoqi.security.biz.mapper.BhTaskUserResumeMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.TableResultResponse;
import com.github.wxiaoqi.security.common.util.Query;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * 任务-猎手关系表（领取表）存储领的任务
 *
 * @author Mr.AG
 * @email 463540703@qq.com
 * @date 2018-05-16 10:29:09
 */
@Service
public class BhReceiveBiz extends BaseBiz<BhReceiveMapper,BhReceive> {
	@Autowired
	private BhTaskUserResumeMapper bhTaskUserResumeMapper;
	/**
	 * 已领取任务列表
	 */
	public TableResultResponse<BhTaskReceive> receiveList(Map<String, Object> reqs) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		String custId = (String) reqs.get("custId");
		String endTimeStart = (String) reqs.get("endTimeStart");
		String endTimeEnd = (String) reqs.get("endTimeEnd");
		String receiveStart = (String) reqs.get("receiveStart");
		String receiveEnd = (String) reqs.get("receiveEnd");
		String receiveTime = (String) reqs.get("receiveTime");
		String taskId = (String) reqs.get("taskId");
		String taskStatus = (String) reqs.get("taskStatus");
		String positionName = (String) reqs.get("positionName");
		String companyName = (String) reqs.get("companyName");
		String page = (String) reqs.get("page");
		String limit = (String) reqs.get("limit");
		
		if(null != endTimeStart && !"".equals(endTimeStart)){
			map.put("endTimeStart", endTimeStart);
			
		}
		if(null != endTimeEnd && !"".equals(endTimeEnd)){
			map.put("endTimeEnd", endTimeEnd);
			
		}
		if(null != receiveStart && !"".equals(receiveStart)){
			map.put("receiveStart", receiveStart);
			
		}
		if(null != receiveEnd && !"".equals(receiveEnd)){
			map.put("receiveEnd", receiveEnd);
			
		}
		if(null != taskId && !"".equals(taskId)){
			map.put("taskId", taskId);
		}
		if(null != taskStatus && !"".equals(taskStatus)){
			map.put("taskStatus", taskStatus);
		}
		if(null != positionName && !"".equals(positionName)){
			map.put("positionName", positionName);
		}
		if(null != companyName && !"".equals(companyName)){
			map.put("companyName", companyName);
		}
		map.put("custId", custId);
		Map<String, Object> params = new HashMap<String, Object>();
		 params.put("page", page);
		 params.put("limit", limit);
		 Query query = new Query(params);
		 PageHelper.startPage(query.getPage(), query.getLimit());
		List<BhTaskReceive> list = mapper.queryReceiveTask(map);
		PageInfo<BhTaskReceive> pageInfo = new PageInfo<BhTaskReceive>(list);
		return new TableResultResponse<BhTaskReceive>(pageInfo.getTotal(), list);
	}
}